<template>
  <div class="page" style="">
    <div class="print_title">任务进度明细 · 禾美环保</div>
    <p class="title">基本信息</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px;">
      <a-col :span="12">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ filterMultiDictText(dictOptions['handlerId'], formData.nodeInfo.handlerId + '') }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请部门:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ filterMultiDictText(dictOptions['handlerDeptId'], formData.nodeInfo.handlerDeptId + '') }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.nodeInfo.createTime }}</p>
          </a-col>
        </a-row>
      </a-col>
    </a-row>
    <p class="title" style="margin-top: 18px">项目信息</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px;">
      <a-col :span="12">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">项目名称:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ filterMultiDictText(dictOptions['projectId'], formData.project.id + '') }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">项目编号:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.project.finalNo }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">经营团队:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ filterMultiDictText(dictOptions['teamName'], formData.project.teamName + '') }}</p>
          </a-col>
        </a-row>
      </a-col>
    </a-row>
    <p class="title" style="margin-top: 18px">任务信息</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px;">
      <a-col :span="12">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">档案编号:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.task.billNo }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">业务分类:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.task.categoryName }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">合同分配额(元):</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.task.contractAmount }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">实施部门:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ filterMultiDictText(dictOptions['handlerDeptId'], formData.task.executeDepart + '') }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">项目负责人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ filterMultiDictText(dictOptions['handlerId'], formData.task.projectLeading + '') }}</p>
          </a-col>
        </a-row>
      </a-col>
    </a-row>
    <a-row type="flex" justify="center" style="margin-top: 18px" v-if="dataSource && dataSource.length">
      <a-col>
        <p class="title_table">任务进度信息</p>
      </a-col>
      <a-col :span="24">
        <a-table
          :columns="columns"
          :data-source="dataSource"
          bordered
          :pagination="false"
          size="small"
          :rowClassName="tableRowClass"></a-table>
      </a-col>
    </a-row>

    <!-- 附件信息 -->
    <FileInfor :purchaseFile="taskFile" title="任务附件" v-if="taskFile && taskFile.length"></FileInfor>
    <!-- 流程详情 -->
    <ProcessInfor v-if="formData.bpmStatus !== '1'" :dataHistorySource="dataHistorySource"></ProcessInfor>
  </div>
</template>
<script>
import { getAction } from '@/api/manage'
import FileInfor from '@/components/print/FileInfor.vue' // 审批历史流程列表组件
import ProcessInfor from '@/components/print/ProcessInfor.vue' // 审批历史流程列表组件
import address from '@/components/AddressChoice/address.js'
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
export default {
  props: {
    formData: {
      type: Object,
      default: () => { },
      required: true
    },
    formDataHistory: {
      type: Object,
      default: () => { },
      required: true
    }
  },
  components: {
    FileInfor,
    ProcessInfor
  },
  data() {
    return {
      address,
      filterMultiDictText,
      dictOptions: {},
      dataSource: [], // 任务进度信息列表
      columns: [
        {
          title: '顺序',
          dataIndex: '',
          key: 'rowIndex',
          width: 44,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '节点名称',
          align: 'center',
          dataIndex: 'nodeName',
          width: 150
        },
        {
          title: '节点进度(%)',
          align: 'center',
          dataIndex: 'nodeProgress',
          width: 85
        },
        {
          title: '消耗工时(天)',
          align: 'center',
          dataIndex: 'consumedHours',
          width: 85
        },
        {
          title: '完成时间',
          align: 'center',
          dataIndex: 'completeTime',
          width: 105
        },
        {
          title: '完成情况',
          align: 'center',
          dataIndex: 'completeDesc'
        },
        {
          title: '证明材料',
          align: 'center',
          dataIndex: 'nodeFile',
          width: 100
        }
      ],
      dataHistorySource: [], // 流程列表
      url: {
        historyList: '/api/erpmng/act/task/processHistoryList' // 流程历史跟踪接口
      },
      taskFile: [] // 附件
    };
  },
  watch: {
    formData: {
      async handler(val) {
        if (val) {
          this.dataSource = val.nodeInfo ? [val.nodeInfo] : []
          this.getHistoryList()
          this.initDictConfig() // 字典值
          // 任务附件
          if (val.task.taskFile) {
            this.taskFile = val.task.taskFile.split(',')
          }
        }
      },
      immediate: true,
      deep: true
    },
    formDataHistory: {
      handler(val) {
        if (val) {
          this.getHistoryList()
        }
      },
      immediate: true
    }
  },
  methods: {
    // 获取列表
    getHistoryList() {
      var params = { processInstanceId: this.formDataHistory.procInsId };// 查询条件
      getAction(this.url.historyList, params).then(res => {
        if (res.success) {
          this.dataHistorySource = res.result.records || res.result
        }
      })
    },

    initDictConfig() {
      // 部门名称
      initDictOptions('sys_depart,depart_name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'handlerDeptId', res.result)
        }
      })
      // 人员名称
      initDictOptions('erp_employee_file,name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'handlerId', res.result)
        }
      })
      // 团队名称
      initDictOptions('erp_omc_team_manager,alias_name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'teamName', res.result)
        }
      })
      // 项目名称
      initDictOptions('erp_omc_project,project_name,id').then(async (res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'projectId', res.result)
        }
      })
    },

    tableRowClass(record, index) {
      console.log('record, index', record, index)
      if (index == 0) {
        return 'rowClass';
      }
      return ''
    }
  }
};
</script>
<style lang="less" scoped>
.page {
  background: #ffffff;
  padding: 19px 28px 0 28px;
  width: 750px;

  .print_title {
    font-size: 15px;
    font-family: Alibaba PuHuiTi 2.0;
    font-weight: normal;
    color: #000000;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 9px;
  }

  .title {
    background: #EEEEEE;
    font-size: 13px;
    font-family: Alibaba PuHuiTi 2.0;
    font-weight: normal;
    color: #000000;
    padding: 11px 9px;
  }

  .title_table {
    font-size: 13px;
    font-family: Alibaba PuHuiTi 2.0;
    font-weight: normal;
    color: #000000;
  }
}

/deep/ .rowClass {
  font-size: 10px;
  font-family: Alibaba PuHuiTi 2.0;
  font-weight: normal;
  color: #000000;
}

/deep/ .ant-table-thead th {
  font-size: 10px;
  font-family: Alibaba PuHuiTi 2.0;
  font-weight: normal;
  color: #000000;
}

/deep/ .ant-table-thead tr {
  background: #EEEEEE;
}

/deep/ .ant-table-small>.ant-table-content>.ant-table-body {
  margin: 0 0px;
}

/deep/ .ant-table-body tr {
  font-size: 10px;
  font-family: Alibaba PuHuiTi 2.0;
  font-weight: normal;
  color: #000000;
}

/deep/ .ant-table-body tr td {
  word-wrap: break-word;
  word-break: break-all;
}

.content {
  font-size: 13px;
}</style>
